package com.xk._01基础篇._03链表;

import com.xk._01基础篇._03链表._循环链表.CircleLinkedList1;
import com.xk.tools.Asserts;

/**
 * @description:
 * @author: xu
 * @date: 2022/9/15 20:12
 */
public class Main {
    public static void main(String[] args) {
        //testList(new CircleLinkedList<>());
        testList(new ArrayList<>());
    }

    private static void josephus(int num){
        CircleLinkedList1<Integer> list = new CircleLinkedList1<>();
        for (int i = 1; i <= 8; i++) {
            list.add(i);
        }
        // 指向头结点
        list.reset();

        while (!list.isEmpty()){
            for (int i = 0; i < num-1; i++) {
                list.next();
            }
            System.out.println(list.remove());
        }
    }

    private static void testList(List<Integer> list){
        list.add(11);
        list.add(22);
        list.add(33);
        list.add(44);
        System.out.println(list);


        list.add(0, 55); // [55, 11, 22, 33, 44]
        System.out.println(list);

        list.add(2, 66); // [55, 11, 66, 22, 33, 44]
        System.out.println(list);

        list.add(list.size(), 77); // [55, 11, 66, 22, 33, 44, 77]
        System.out.println(list);

        list.remove(0);// [11, 66, 22, 33, 44, 77]
        System.out.println(list);

        list.remove(2);// [11, 66, 33, 44, 77]
        System.out.println(list);

        list.remove(4);// [11, 66, 33, 44]
        System.out.println(list);

        Asserts.test(list.indexOf(44) == 3);
        Asserts.test(list.indexOf(22) == List.ELEMENT_NOT_FOUND);
        Asserts.test(list.contains(11));
        Asserts.test(list.get(0) == 11);
        Asserts.test(list.get(1) == 66);
        Asserts.test(list.get(list.size() - 1) == 44);
    }
}
